﻿<UserControl x:Class="QuickMail.View.Controls.LettersControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="870"
             FontSize="14">
    <Control.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../../ResourceDictionary.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <Style x:Key="LetterItemsStyle" TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource {x:Type ListViewItem}}">
                <EventSetter Event="MouseDoubleClick" Handler="LetterItem_OnMouseDoubleClick" />
                <EventSetter Event="MouseEnter" Handler="LetterItem_OnMouseEnter" />
            </Style>
        </ResourceDictionary>
    </Control.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Popup x:Name="AttachmentsPopup" Placement="MousePoint" MaxWidth="500" MinWidth="150"
               StaysOpen="False" AllowsTransparency="True" PopupAnimation="Fade">
            <Border Background="#086F9E">
                <!--<Border Background="#008DB5"> my color-->
                <!--<Border BorderThickness="2" BorderBrush="#086F9E" Background="#086F9E"> mahapps darkblue-->
                <!--<Border BorderThickness="2" BorderBrush="#41B1E1" Background="#41B1E1">-->
                <!--<Border BorderThickness="2" BorderBrush="#00A7D1" Background="#00A7D1">-->
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>

                    <ScrollViewer Grid.Row="0" Grid.Column="0" Margin="0" MaxHeight="300" VerticalScrollBarVisibility="Auto">
                        <WrapPanel x:Name="AttachmentsWrapPanel" HorizontalAlignment="Center" />
                    </ScrollViewer>
                    <Button Grid.Row="0" Grid.Column="1" Width="25" Height="25" 
                            Click="ClosePopup_OnClick" ToolTip="Close"
                            HorizontalAlignment="Right" VerticalAlignment="Top" Margin="5">
                        <Image Source="../../Resources/delete_sign-32.png" Margin="-3"/>
                    </Button>
                    <Button Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Click="OpenFolder_OnClick"
                            Margin="5" Height="35">
                        <StackPanel Orientation="Horizontal">
                            <Image Source="../../Resources/opened_folder-32.png" Margin="5, 0"/>
                            <TextBlock x:Name="OpenFolderTextBlock" Text="OPEN FOLDER" FontSize="12" VerticalAlignment="Center"/>
                        </StackPanel>
                    </Button>
                </Grid>
            </Border>
        </Popup>

        <ListView Grid.Row="0" x:Name="LettersListView" ItemContainerStyle="{StaticResource LetterItemsStyle}">
            <ListView.ContextMenu>
                <ContextMenu>
                    <MenuItem x:Name="DeleteMenuItem" Header="Delete" Click="DeleteButton_OnClick">
                        <MenuItem.Icon>
                            <Image Width="22" Source="../../Resources/trash-32.png" Margin="4"/>
                        </MenuItem.Icon>
                    </MenuItem>
                </ContextMenu>
            </ListView.ContextMenu>
            <ListView.View>
                <GridView>
                    <GridView.Columns>
                        <GridViewColumn Width="30">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <Image Width="18" Source="{Binding Path=StatusImage}"/>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                            <GridViewColumn.Header>
                                <GridViewColumnHeader Tag="Type" Click="LettersSort_OnClick"/>
                            </GridViewColumn.Header>
                        </GridViewColumn>

                        <GridViewColumn Width="200" DisplayMemberBinding="{Binding Path=From}">
                            <GridViewColumn.Header>
                                <GridViewColumnHeader x:Name="FromColumn" Tag="From" Content="From" Click="LettersSort_OnClick"/>
                            </GridViewColumn.Header>
                        </GridViewColumn>

                        <GridViewColumn Width="200"
                                        DisplayMemberBinding="{Binding Path=To}">
                            <GridViewColumn.Header>
                                <GridViewColumnHeader x:Name="ToColumn" Tag="To" Content="To" Click="LettersSort_OnClick"/>
                            </GridViewColumn.Header>
                        </GridViewColumn>

                        <GridViewColumn Width="200"
                                        DisplayMemberBinding="{Binding Path=Subject}">
                            <GridViewColumn.Header>
                                <GridViewColumnHeader x:Name="SubjectColumn" Tag="Subject" Content="Subject" Click="LettersSort_OnClick"/>
                            </GridViewColumn.Header>
                        </GridViewColumn>

                        <GridViewColumn Width="200"
                                        DisplayMemberBinding="{Binding Path=LetterDate, StringFormat=f}">
                            <GridViewColumn.Header>
                                <GridViewColumnHeader x:Name="DateColumn" Tag="LetterDate" Content="Date and time" Click="LettersSort_OnClick"/>
                            </GridViewColumn.Header>
                        </GridViewColumn>

                        <GridViewColumn x:Name="AttachmentsColumn" Width="40" >
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <Button x:Name="AttachmentsButton" 
                                            Style="{StaticResource AttachmentButtonStyle}" 
                                            Click="ShowAttachments_OnClick"/>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                    </GridView.Columns>
                </GridView>
            </ListView.View>
        </ListView>

        <Rectangle Grid.Row="1" Fill="#00FFFFFF" MouseDown="UnselectLetter_OnMouseDown"/>
    </Grid>
</UserControl>
